var ag=0;
var ccindexParam = {
		pageNum: 1,
		limit: 5
}
var ccCallRecord ="";
$(function () {
	
	 if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//全部电话记录单
    $.ajax({	
        url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
        type: "GET",
//        timeout : 15000,
        data:{ 
   		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
   		  'start':startRecord,
 	      'limit':ccindexParam.limit
          },
        success: function (data) {

        	//分页

        	if (data.success) {
        	var dataCount = parseInt(data.totalCount);
            var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
            var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
            var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
            var isFirst = ccindexParam.pageNum <= 1;
            var isLast = ccindexParam.pageNum >= totalPage;
            var ccIndexPage = {
                currentPage: ccindexParam.pageNum,
                dataCount: dataCount,
                totalPage: totalPage,
                prePage: prePage,
                nextPage: nextPage,
                isFirst: isFirst,
                isLast: isLast
            }}
        	 //显示页数数组
            var pageArr = new Array();
            if (totalPage <= 5) { // 总页数
                for (var i = 1; i <= totalPage; i++) {
                    pageArr.push(i);
                }
            } else {
                if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
                    for (var i = 0; i < 5; i++) {
                        pageArr[i] = ccindexParam.pageNum - 2 + i;
                    }
                } else if (ccindexParam.pageNum <= 2) {
                    pageArr = [1, 2, 3, 4, 5];
                } else {
                    for (var i = 0; i < 5; i++) {
                        pageArr[i] = totalPage - 4 + i;
                    }
                }
            }
            var $pageContainer = $('#pageContainer');
            
            // 创建中间部分页码
            var pageNumHtml =
                '<li class="">' +
                    '<a href="javascript:void(0)">{pageNum}</a>' +
                '</li>';
            $.each(pageArr, function (index, item) {
                var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
                if (ccIndexPage.currentPage == item) {
                    $pageNum.addClass('active');
                }
                $pageNum.click(function () {
                	$("#pageContainer li.active").removeClass('active');
                	ccindexParam.pageNum = item;
                	$pageNum.addClass('active');
                		if(ccindexParam.pageNum==1){
                    		startRecord=0;
                    	}else{
                    		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
                    	}
                		var res=ccindexParam.pageNum;
                		pageForAllRecords(res);
                		
                	
                });
                $pageContainer.append($pageNum);
            });
            //全部
            forEachAllCcdata(data,'telRecord_all');
    	},
        error: function (httpRequest) {
        	console.log("未知异常");
        }
    });
});
//点击全部	
function clickAllRecords(){
	var ccindexParam = {
			pageNum: 1,
			limit: 5
	}
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
 $.ajax({	
     url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
     type: "GET",
     data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'start':startRecord,
	      'limit':ccindexParam.limit
       },
     success: function (data) {

     	//分页
     	if (data.success) {
     	var dataCount = parseInt(data.totalCount);
         var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
         var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
         var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
         var isFirst = ccindexParam.pageNum <= 1;
         var isLast = ccindexParam.pageNum >= totalPage;
         var ccIndexPage = {
             currentPage: ccindexParam.pageNum,
             dataCount: dataCount,
             totalPage: totalPage,
             prePage: prePage,
             nextPage: nextPage,
             isFirst: isFirst,
             isLast: isLast
         }}
     	$('#pageContainer').empty();
     	 //显示页数数组
         var pageArr = new Array();
         if (totalPage <= 5) { // 总页数
             for (var i = 1; i <= totalPage; i++) {
                 pageArr.push(i);
             }
         } else {
             if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = ccindexParam.pageNum - 2 + i;
                 }
             } else if (ccindexParam.pageNum <= 2) {
                 pageArr = [1, 2, 3, 4, 5];
             } else {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = totalPage - 4 + i;
                 }
             }
         }
         var $pageContainer = $('#pageContainer');
         
         // 创建中间部分页码
         var pageNumHtml =
             '<li class="">' +
                 '<a href="javascript:void(0)">{pageNum}</a>' +
             '</li>';
         $.each(pageArr, function (index, item) {
             var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
             if (ccIndexPage.currentPage == item) {
                 $pageNum.addClass('active');
             }
             $pageNum.click(function () {
            	 $("#pageContainer li.active").removeClass('active');
             	ccindexParam.pageNum = item;
             	$pageNum.addClass('active');
             	
             		if(ccindexParam.pageNum==1){
                 		startRecord=0;
                 	}else{
                 		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
                 	}
             		var res=ccindexParam.pageNum;
             		pageForAllRecords(res);
             });
             $pageContainer.append($pageNum);
         });
         
         forEachAllCcdata(data,'telRecord_all');


     	},
     error: function (httpRequest) {
     	console.log("未知异常");
     }
 });
}


//加载全部分页	
function pageForAllRecords(res){
	if(res==undefined){
		 res=ccindexParam.pageNum;
	 }
	 ccindexParam.pageNum =res;
	 
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
 $.ajax({	
     url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
     type: "GET",
     data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'start':startRecord,
	      'limit':ccindexParam.limit
       },
     success: function (data) {
     	//分页
     	if (data.success) {
     	var dataCount = parseInt(data.totalCount);
         var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
         var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
         var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
         var isFirst = ccindexParam.pageNum <= 1;
         var isLast = ccindexParam.pageNum >= totalPage;
         var ccIndexPage = {
             currentPage: ccindexParam.pageNum,
             dataCount: dataCount,
             totalPage: totalPage,
             prePage: prePage,
             nextPage: nextPage,
             isFirst: isFirst,
             isLast: isLast
         }}
     	$('#pageContainer').empty();
     	 //显示页数数组
         var pageArr = new Array();
         if (totalPage <= 5) { // 总页数
             for (var i = 1; i <= totalPage; i++) {
                 pageArr.push(i);
             }
         } else {
             if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = ccindexParam.pageNum - 2 + i;
                 }
             } else if (ccindexParam.pageNum <= 2) {
                 pageArr = [1, 2, 3, 4, 5];
             } else {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = totalPage - 4 + i;
                 }
             }
         }
         var $pageContainer = $('#pageContainer');
         
         // 创建中间部分页码
         var pageNumHtml =
             '<li class="">' +
                 '<a href="javascript:void(0)">{pageNum}</a>' +
             '</li>';
         $.each(pageArr, function (index, item) {
             var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
             if (ccIndexPage.currentPage == item) {
                 $pageNum.addClass('active');
             }
             $pageNum.click(function () {
            	 $("#pageContainer li.active").removeClass('active');
             	ccindexParam.pageNum = item;
             	ccIndexPage.currentPage = item;
             	$pageNum.addClass('active');
             	
             		if(ccindexParam.pageNum==1){
                 		startRecord=0;
                 	}else{
                 		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
                 	}
             		pageForAllRecords();
             });
             $pageContainer.append($pageNum);
         });
         
         forEachAllCcdata(data,'telRecord_all');

     	},
     error: function (httpRequest) {
     	console.log("未知异常");
     }
 });
}


//全部
function forEachAllCcdata(data,idnum){

    if(undefined==data.callServiceVo||0==data.callServiceVo.callServiceList.length){
        $("#"+idnum+" .telRecordBox").css("display","none");
        $("#"+idnum+" .telRecord-null").css("display","block");
    }else{
        $("#"+idnum+" .telRecord-null").css("display","none");
        $("#"+idnum+" .telRecordBox").css("display","block");
        $("#"+idnum+" tbody").empty();
        if(data.callServiceVo==null || data.callServiceVo==undefined ) {
            return;
        }
      for (var i = 0; i <data.callServiceVo.callServiceList.length; i++) {

          var ccTableSpan = '<span class="glyphicon glyphicon-time table_span"></span>'
          //转换中文显示
          if(data.callServiceVo.callServiceList[i].serviceStatus=="PROCESSING"){
              data.callServiceVo.callServiceList[i].serviceStatus="处理中";
          }
          if(data.callServiceVo.callServiceList[i].serviceStatus=="FOLLOWUP"){
              data.callServiceVo.callServiceList[i].serviceStatus="待跟进";
          }
          if(data.callServiceVo.callServiceList[i].serviceStatus=="FINISH"){
              data.callServiceVo.callServiceList[i].serviceStatus="已处理";
          }
          var index =i+1;
          if(data.callServiceVo.callServiceList[i].callOnTime == null){
              var callOnTime = '';
          }else{
              var createDate =new Date(data.callServiceVo.callServiceList[i].callOnTime);
              var callOnTime = createDate.format("yyyy-MM-dd hh:mm:ss");
          }

          if(data.callServiceVo.callServiceList[i].callOffTime == null){
              var callOffTime = '';
          }else{
              var createDate =new Date(data.callServiceVo.callServiceList[i].callOffTime);
              var callOffTime = createDate.format("yyyy-MM-dd hh:mm:ss");
          }

          if(data.callServiceVo.callServiceList[i].serviceId==null||data.callServiceVo.callServiceList[i].serviceId==undefined){
              data.callServiceVo.callServiceList[i].serviceId="";
          }
          if(data.callServiceVo.callServiceList[i].custName==null||data.callServiceVo.callServiceList[i].custName==undefined){
              data.callServiceVo.callServiceList[i].custName="";
          }
          if(data.callServiceVo.callServiceList[i].custphonenum==null||data.callServiceVo.callServiceList[i].custphonenum==undefined){
              data.callServiceVo.callServiceList[i].custphonenum="";
          }
          var str = '<tr onclick="getCallRecord(this)">'+
              '<td><span class="check-span"><input type="checkbox" class="ccCheckbox" name="ccCheckbox" value="'+ data.callServiceVo.callServiceList[i].serviceId+'" ></span></td>'+
              '<td>'+index+'</td>'+
              '<td><div class="telServiceId" title="'+data.callServiceVo.callServiceList[i].serviceId+'">'+data.callServiceVo.callServiceList[i].serviceId+'</div></td>'+
              '<td><button><img src="resources/img/call-in.png"></button></td>'+
              '<td><div class="telCustName" title="'+data.callServiceVo.callServiceList[i].custName+'">'+data.callServiceVo.callServiceList[i].custName+'</div></td>'+
              '<td><div class="telCustPhonenum" title="'+data.callServiceVo.callServiceList[i].custphonenum+'">'+data.callServiceVo.callServiceList[i].custphonenum+'</div></td>'+
              '<td><label class="label label-primary">'+data.callServiceVo.callServiceList[i].serviceStatus+'</label></td>'+
              '<td>'+callOnTime+'</td>'+
              '<td>'+callOffTime+'</td>'+
              '</tr>';

          var serviceStatus=data.callServiceVo.callServiceList[i].serviceStatus;
      	if(data.callServiceVo.callServiceList[i].callType=='CALLIN'){
            if(serviceStatus == '处理中' || serviceStatus == '待跟进' || serviceStatus == '已处理'){
                $("#"+idnum+" tbody").append(str);
                $("#"+idnum+" tbody tr:nth-child("+(i+1)+") td:nth-child(4) button img").attr("src","resources/img/call-in.png");
            }
        }else if(data.callServiceVo.callServiceList[i].callType=='CALLOUT'){
            if(serviceStatus == '处理中' || serviceStatus == '待跟进' || serviceStatus == '已处理'){
                $("#"+idnum+" tbody").append(str);
                $("#"+idnum+" tbody tr:nth-child("+(i+1)+") td:nth-child(4) button img").attr("src","resources/img/call-out.png");
            }
        }
          isTimeNull(callOnTime,callOffTime,ccTableSpan,i,idnum);


      		$("input[name='ccCheckbox']").click(function(){
      			ccCallRecord=$(".ccCheckbox:checked").val();
      			
      	 });
      }
  }
}

function isTimeNull(cc1,cc2,ccTableSpan,i,idnum) {
    if(cc1!=''){
        $('#'+idnum+' tbody tr:nth-child('+(i+1)+') td:nth-child(8)').prepend(ccTableSpan)
    }
    if(cc2!=''){
        $('#'+idnum+' tbody tr:nth-child('+(i+1)+') td:nth-child(9)').prepend(ccTableSpan)
    }
}

//点击已处理	
function clickFinish(){
	var ccindexParam = {
			pageNum: 1,
			limit: 5
	}
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
$.ajax({	
   url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
   type: "GET",
   data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'callServiceVo.callServiceEntity.serviceStatus': 'FINISH',
		  'start':startRecord,
	      'limit':ccindexParam.limit
     },
   success: function (data) {

   	//分页
   	if (data.success) {
   	var dataCount = parseInt(data.totalCount);
       var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
       var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
       var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
       var isFirst = ccindexParam.pageNum <= 1;
       var isLast = ccindexParam.pageNum >= totalPage;
       var ccIndexPage = {
           currentPage: ccindexParam.pageNum,
           dataCount: dataCount,
           totalPage: totalPage,
           prePage: prePage,
           nextPage: nextPage,
           isFirst: isFirst,
           isLast: isLast
       }}
   	$('#finishPageContainer').empty();
   	 //显示页数数组
       var pageArr = new Array();
       if (totalPage <= 5) { // 总页数
           for (var i = 1; i <= totalPage; i++) {
               pageArr.push(i);
           }
       } else {
           if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
               for (var i = 0; i < 5; i++) {
                   pageArr[i] = ccindexParam.pageNum - 2 + i;
               }
           } else if (ccindexParam.pageNum <= 2) {
               pageArr = [1, 2, 3, 4, 5];
           } else {
               for (var i = 0; i < 5; i++) {
                   pageArr[i] = totalPage - 4 + i;
               }
           }
       }
       var $pageContainer = $('#finishPageContainer');
       
       // 创建中间部分页码
       var pageNumHtml =
           '<li class="">' +
               '<a href="javascript:void(0)">{pageNum}</a>' +
           '</li>';
       $.each(pageArr, function (index, item) {
           var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
           if (ccIndexPage.currentPage == item) {
               $pageNum.addClass('active');
           }
           $pageNum.click(function () {
          	 $("#finishPageContainer li.active").removeClass('active');
           	ccindexParam.pageNum = item;
           	$pageNum.addClass('active');
           	
           		if(ccindexParam.pageNum==1){
               		startRecord=0;
               	}else{
               		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
               	}
           		var res=ccindexParam.pageNum;
           		pageForFinish(res);
           });
           $pageContainer.append($pageNum);
       });

       forEachAllCcdata(data,'telRecord_pending');

   	},
   error: function (httpRequest) {
   	console.log("未知异常");
   }
});
}

//加载已处理分页
function pageForFinish(res){
	if(res==undefined){
		 res=ccindexParam.pageNum;
	}
	ccindexParam.pageNum =res;
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
$.ajax({	
   url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
   type: "GET",
   data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'callServiceVo.callServiceEntity.serviceStatus': 'FINISH',
		  'start':startRecord,
	      'limit':ccindexParam.limit
     },
   success: function (data) {
   	//分页
   	if (data.success) {
   	var dataCount = parseInt(data.totalCount);
       var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
       var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
       var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
       var isFirst = ccindexParam.pageNum <= 1;
       var isLast = ccindexParam.pageNum >= totalPage;
       var ccIndexPage = {
           currentPage: ccindexParam.pageNum,
           dataCount: dataCount,
           totalPage: totalPage,
           prePage: prePage,
           nextPage: nextPage,
           isFirst: isFirst,
           isLast: isLast
       }}
   	$('#finishPageContainer').empty();
   	 //显示页数数组
       var pageArr = new Array();
       if (totalPage <= 5) { // 总页数
           for (var i = 1; i <= totalPage; i++) {
               pageArr.push(i);
           }
       } else {
           if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
               for (var i = 0; i < 5; i++) {
                   pageArr[i] = ccindexParam.pageNum - 2 + i;
               }
           } else if (ccindexParam.pageNum <= 2) {
               pageArr = [1, 2, 3, 4, 5];
           } else {
               for (var i = 0; i < 5; i++) {
                   pageArr[i] = totalPage - 4 + i;
               }
           }
       }
       var $pageContainer = $('#finishPageContainer');
       
       // 创建中间部分页码
       var pageNumHtml =
           '<li class="">' +
               '<a href="javascript:void(0)">{pageNum}</a>' +
           '</li>';
       $.each(pageArr, function (index, item) {
           var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
           if (ccIndexPage.currentPage == item) {
               $pageNum.addClass('active');
           }
           $pageNum.click(function () {
          	 $("#finishPageContainer li.active").removeClass('active');
           	ccindexParam.pageNum = item;
           	ccIndexPage.currentPage = item;
           	$pageNum.addClass('active');
           	
           		if(ccindexParam.pageNum==1){
               		startRecord=0;
               	}else{
               		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
               	}
           		pageForFinish();
           });
           $pageContainer.append($pageNum);
       });

       forEachAllCcdata(data,'telRecord_pending');

   	},
   error: function (httpRequest) {
   	console.log("未知异常");
   }
});
}

//点击处理中	
function clickProcessing(){
	var ccindexParam = {
			pageNum: 1,
			limit: 5
	}
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
 $.ajax({	
     url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
     type: "GET",
     data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'callServiceVo.callServiceEntity.serviceStatus': 'PROCESSING',
		  'start':startRecord,
	      'limit':ccindexParam.limit
       },
     success: function (data) {

     	//分页
     	if (data.success) {
     	var dataCount = parseInt(data.totalCount);
         var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
         var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
         var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
         var isFirst = ccindexParam.pageNum <= 1;
         var isLast = ccindexParam.pageNum >= totalPage;
         var ccIndexPage = {
             currentPage: ccindexParam.pageNum,
             dataCount: dataCount,
             totalPage: totalPage,
             prePage: prePage,
             nextPage: nextPage,
             isFirst: isFirst,
             isLast: isLast
         }}
     	$('#processingPageContainer').empty();
     	 //显示页数数组
         var pageArr = new Array();
         if (totalPage <= 5) { // 总页数
             for (var i = 1; i <= totalPage; i++) {
                 pageArr.push(i);
             }
         } else {
             if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = ccindexParam.pageNum - 2 + i;
                 }
             } else if (ccindexParam.pageNum <= 2) {
                 pageArr = [1, 2, 3, 4, 5];
             } else {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = totalPage - 4 + i;
                 }
             }
         }
         var $pageContainer = $('#processingPageContainer');
         
         // 创建中间部分页码
         var pageNumHtml =
             '<li class="">' +
                 '<a href="javascript:void(0)">{pageNum}</a>' +
             '</li>';
         $.each(pageArr, function (index, item) {
             var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
             if (ccIndexPage.currentPage == item) {
                 $pageNum.addClass('active');
             }
             $pageNum.click(function () {
            	 $("#processingPageContainer li.active").removeClass('active');
             	ccindexParam.pageNum = item;
             	$pageNum.addClass('active');
             	
             		if(ccindexParam.pageNum==1){
                 		startRecord=0;
                 	}else{
                 		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
                 	}
             		var res=ccindexParam.pageNum;
             		pageForProcessing(res);
             });
             $pageContainer.append($pageNum);
         });
         //加载数据
         forEachAllCcdata(data,'telRecord_dealing');
     	},
     error: function (httpRequest) {
     	console.log("未知异常");
     }
 });
}

//加载处理中分页	
function pageForProcessing(res){
	if(res==undefined){
		 res=ccindexParam.pageNum;
	}
	ccindexParam.pageNum =res;
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
 $.ajax({	
     url: CCS_SERVER_NAME+"/call-web/callin/queryCallService.action",
     type: "GET",
     data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'callServiceVo.callServiceEntity.serviceStatus': 'PROCESSING',
		  'start':startRecord,
	      'limit':ccindexParam.limit
       },
     success: function (data) {
     	//分页
     	if (data.success) {
     	var dataCount = parseInt(data.totalCount);
         var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
         var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
         var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
         var isFirst = ccindexParam.pageNum <= 1;
         var isLast = ccindexParam.pageNum >= totalPage;
         var ccIndexPage = {
             currentPage: ccindexParam.pageNum,
             dataCount: dataCount,
             totalPage: totalPage,
             prePage: prePage,
             nextPage: nextPage,
             isFirst: isFirst,
             isLast: isLast
         }}
     	$('#processingPageContainer').empty();
     	 //显示页数数组
         var pageArr = new Array();
         if (totalPage <= 5) { // 总页数
             for (var i = 1; i <= totalPage; i++) {
                 pageArr.push(i);
             }
         } else {
             if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = ccindexParam.pageNum - 2 + i;
                 }
             } else if (ccindexParam.pageNum <= 2) {
                 pageArr = [1, 2, 3, 4, 5];
             } else {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = totalPage - 4 + i;
                 }
             }
         }
         var $pageContainer = $('#processingPageContainer');
         
         // 创建中间部分页码
         var pageNumHtml =
             '<li class="">' +
                 '<a href="javascript:void(0)">{pageNum}</a>' +
             '</li>';
         $.each(pageArr, function (index, item) {
             var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
             if (ccIndexPage.currentPage == item) {
                 $pageNum.addClass('active');
             }
             $pageNum.click(function () {
            	 $("#processingPageContainer li.active").removeClass('active');
             	ccindexParam.pageNum = item;
             	ccIndexPage.currentPage = item;
             	$pageNum.addClass('active');
             	
             		if(ccindexParam.pageNum==1){
                 		startRecord=0;
                 	}else{
                 		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
                 	}
             		pageForProcessing();
             });
             $pageContainer.append($pageNum);
         });

         forEachAllCcdata(data,'telRecord_dealing');

     	},
     error: function (httpRequest) {
     	console.log("未知异常");
     }
 });
}

//点击待跟进
function clickPending(){
	
	var ccindexParam = {
			pageNum: 1,
			limit: 5
	}
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
 $.ajax({	
     url: CCS_SERVER_NAME+"/call-web/callin/queryCallService.action",
     type: "GET",
     data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'callServiceVo.callServiceEntity.serviceStatus': 'FOLLOWUP',
		  'start':startRecord,
	      'limit':ccindexParam.limit
       },
     success: function (data) {

     	//分页
     	if (data.success) {
     	var dataCount = parseInt(data.totalCount);
         var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
         var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
         var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
         var isFirst = ccindexParam.pageNum <= 1;
         var isLast = ccindexParam.pageNum >= totalPage;
         var ccIndexPage = {
             currentPage: ccindexParam.pageNum,
             dataCount: dataCount,
             totalPage: totalPage,
             prePage: prePage,
             nextPage: nextPage,
             isFirst: isFirst,
             isLast: isLast
         }}
     	$('#followUpPageContainer').empty();
     	 //显示页数数组
         var pageArr = new Array();
         if (totalPage <= 5) { // 总页数
             for (var i = 1; i <= totalPage; i++) {
                 pageArr.push(i);
             }
         } else {
             if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = ccindexParam.pageNum - 2 + i;
                 }
             } else if (ccindexParam.pageNum <= 2) {
                 pageArr = [1, 2, 3, 4, 5];
             } else {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = totalPage - 4 + i;
                 }
             }
         }
         var $pageContainer = $('#followUpPageContainer');
         
         // 创建中间部分页码
         var pageNumHtml =
             '<li class="">' +
                 '<a href="javascript:void(0)">{pageNum}</a>' +
             '</li>';
         $.each(pageArr, function (index, item) {
             var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
             if (ccIndexPage.currentPage == item) {
                 $pageNum.addClass('active');
             }
             $pageNum.click(function () {
            	 $("#followUpPageContainer li.active").removeClass('active');
             	ccindexParam.pageNum = item;
             	$pageNum.addClass('active');
             	
             		if(ccindexParam.pageNum==1){
                 		startRecord=0;
                 	}else{
                 		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
                 	}
             		var res=ccindexParam.pageNum;
             		pageForPending(res);
             });
             $pageContainer.append($pageNum);
         });

         forEachAllCcdata(data,'telRecord_processed');

     	},
     error: function (httpRequest) {
     	console.log("未知异常");
     }
 });
}

//加载待跟进分页
function pageForPending(res){
	 if(res==undefined){
		 res=ccindexParam.pageNum;
	 }
	 ccindexParam.pageNum =res;
	if(ccindexParam.pageNum==1){
		 var startRecord =0;
	 }else{
		 var startRecord =(ccindexParam.pageNum-1)*5;
	 }
	//电话记录单
 $.ajax({	
     url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
     type: "GET",
     data:{ 
		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode,
		  'callServiceVo.callServiceEntity.serviceStatus': 'FOLLOWUP',
		  'start':startRecord,
	      'limit':ccindexParam.limit
       },
     success: function (data) {
     	//分页
     	if (data.success) {
     	var dataCount = parseInt(data.totalCount);
         var totalPage = Math.floor((dataCount +  ccindexParam.limit - 1) / ccindexParam.limit);
         var prePage = ccindexParam.pageNum > 1 ? ccindexParam.pageNum - 1 : 1
         var nextPage = ccindexParam.pageNum < totalPage ? ccindexParam.pageNum + 1 : totalPage;
         var isFirst = ccindexParam.pageNum <= 1;
         var isLast = ccindexParam.pageNum >= totalPage;
         var ccIndexPage = {
             currentPage: ccindexParam.pageNum,
             dataCount: dataCount,
             totalPage: totalPage,
             prePage: prePage,
             nextPage: nextPage,
             isFirst: isFirst,
             isLast: isLast
         }}
     	$('#followUpPageContainer').empty();
     	 //显示页数数组
         var pageArr = new Array();
         if (totalPage <= 5) { // 总页数
             for (var i = 1; i <= totalPage; i++) {
                 pageArr.push(i);
             }
         } else {
             if (ccindexParam.pageNum + 2 <= totalPage && ccindexParam.pageNum - 2 > 0) {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = ccindexParam.pageNum - 2 + i;
                 }
             } else if (ccindexParam.pageNum <= 2) {
                 pageArr = [1, 2, 3, 4, 5];
             } else {
                 for (var i = 0; i < 5; i++) {
                     pageArr[i] = totalPage - 4 + i;
                 }
             }
         }
         var $pageContainer = $('#followUpPageContainer');
         
         // 创建中间部分页码
         var pageNumHtml =
             '<li class="">' +
                 '<a href="javascript:void(0)">{pageNum}</a>' +
             '</li>';
         $.each(pageArr, function (index, item) {
             var $pageNum = $(pageNumHtml.replace('{pageNum}', item));
             if (ccIndexPage.currentPage == item) {
                 $pageNum.addClass('active');
             }
             $pageNum.click(function () {
            	 $("#followUpPageContainer li.active").removeClass('active');
             	ccindexParam.pageNum = item;
             	ccIndexPage.currentPage = item;
             	$pageNum.addClass('active');
             	
             		if(ccindexParam.pageNum==1){
                 		startRecord=0;
                 	}else{
                 		startRecord=(ccindexParam.pageNum-1)*ccindexParam.limit;
                 	}
             		pageForPending();
             });
             $pageContainer.append($pageNum);
         });

         forEachAllCcdata(data,'telRecord_processed');

     	},
     error: function (httpRequest) {
     	console.log("未知异常");
     }
 });
}

//首页点击查询全部按钮，跳转电话记录单界面
function skipCallMangement(){
	viewTab("电话记录单管理", CCS_SERVER_NAME+"call-web/callin/callInManagerIndex.action","div");
}

//查询服务编码
function queryCcServiceId(){
	var serviceId=$.trim($("#queryServiceid").val());
	if(serviceId==null || serviceId==""){
		checktip($("#queryServiceid"), '请输入单号');
		return;
	}else{
		 $.ajax({	
	         url: CCS_SERVER_NAME+"call-web/callin/queryCallService.action",
	         type: "GET",
	         data:{ 
	    		  'callServiceVo.callServiceEntity.createUser': userInfo.empCode, //userInfo.empCode 000000
	    		  'callServiceVo.callServiceEntity.serviceId': serviceId, //userInfo.empCode 000000
	    		  'start':'0',
	    		  'limit':'5'
	           },
	 	        success: function (data) {
	 	        	if (data.totalCount ==0){
	 	        		checktip($("#queryServiceid"), '没有查询到该单号数据');
	 	        		return;
	 	        	}
	 	        	forEachAllCcdata(data,'telRecord_all');
	 	        	$('#pageContainer').empty();
                    forEachAllCcdata(data,'telRecord_pending');
	 	        	$("#finishPageContainer").empty();
                    forEachAllCcdata(data,'telRecord_processed');
	 	        	$("#followUpPageContainer").empty();
                    forEachAllCcdata(data,'telRecord_dealing');
	 	        	$("#processingPageContainer").empty();
	 	        },
	 	        error: function (httpRequest) {
	 	        	console.log("未知异常");
	 	        }
	 	    });
	}
	
}

function getCallRecord(thiscontent){
	var checklength = $(".ccCheckbox:checked").length;
	if( checklength>1){
		$(".check-span").removeClass("checked");
		$(".ccCheckbox").attr("checked",false);
		ccCallRecord="";
//		ccCallRecord=thiscontent.childNodes[2].childNodes[0].textContent;
		alert("只能选中一条数据");
	}
}

function keyDown2(e) {
	var ev= window.event||e;
	// 回车键
	if (ev.keyCode == 13) {
		queryCcServiceId();
    }
}

	 
